package cn.tedu.charging.device.controller;


import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.service.DeviceService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="设备接口")
@Slf4j
@RestController
@RequestMapping("device")
public class DeviceController {
    @Autowired
    DeviceService deviceService;
    /**
     * 获取站场信息
     * @return
     */

    @ApiOperation("获取站场信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult<StationInfoVO>  getStationInfo(@PathVariable("gunId") Integer gunId){
        log.debug("获取站场信息：{}",gunId);
        StationInfoVO stationInfoVO = deviceService.getStationInfo(gunId);
        return JsonResult.ok(stationInfoVO,"获取站场信息成功");
    }

    /*
    * 获取附近场站信息
    * */
    @ApiOperation("获取附近场站信息")
    @GetMapping("/station/near")
    public JsonResult<List<StationInfoVO>> getNearStation(@RequestParam("longitude") Double longitude,
                                                          @RequestParam("latitude") Double latitude,
                                                          @RequestParam("distance") Double distance){
        log.debug("获取附近场站信息：{}",longitude+","+latitude+","+distance);
        List<StationInfoVO> stationInfoVOS = deviceService.getNearStation(longitude, latitude, distance);

        return JsonResult.ok(stationInfoVOS,"获取附近场站信息成功");

    }




    /*
    * 更新枪状态
    * */

    @ApiOperation("更新枪状态")
    @PostMapping("/station/gun/status/update")
    public JsonResult<Boolean> updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam){
        log.info("更新枪状态：{}", gunStatusUpdateParam);
        Boolean success=deviceService.updateGunStatus(gunStatusUpdateParam);
        return JsonResult.ok(success,"更新枪状态成功");
    }




}
